// xc_lshop/shop/pro/consignment/mylist.js
var actbill = require('../../model/order_bill')

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],
  
  /**
   * 页面的初始数据
   */
  data: {
    consigninfor:{
      total:0,
      count:0
    },
    searchdata:{
      startdate:"",
      enddate:"",
      auth:"user",//权限user用户订单
      status:'0',
    },
    calendarshow:false,
    minDate: new Date(2021, 7, 1).getTime(),
    maxDate: new Date().getTime(),
    isempty:false

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  xcloaddata: function (options, config) {
    if(config.rebate){
      this.setData({
        rebateconfig:config.rebate
      })
    }
    var that=this;
    that.getmylistinfo();
    that.getpagelist(that,1)
 },
 getmylistinfo(){
  actbill.getmylistinfo().then(res => {

    if (res["status"] == 1) {
      this.setData({
        consigninfor:res["obj"]
      })
    }
  })
 },
 getpagelist(that, rest, strwhere) {
  if (rest == 1) {
    if (!strwhere) {
      strwhere = this.data.searchdata
    }
    that.setData({
      modellist: [],
      isempty: false
    });
  }
  actbill.consignoffset(that, rest, strwhere).then(function (result) {
    var updatemdoel = {};
    if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {
      if (result["obj"]["modellist"].length < 1) {
        updatemdoel["isempty"] = true
      } else if (rest == 1) {
        updatemdoel["modellist"] = result["obj"]["modellist"];
      } else {
        if (result["obj"]["modellist"].length > 0) {
          updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
        }
      }
    }
    // that.selectComponent("#ordercomment").showmodel( updatemdoel["modellist"][0],"order")      
    wx.stopPullDownRefresh();
 
    that.setData(updatemdoel);
  }, function () {

  });
},
  showcalendar(){
    this.setData({
      calendarshow:true
    })
  },
  onChange(e){
     this.setData({
       'searchdata.status':e.detail.name
     })
     var that=this;
     that.getpagelist(that,1)
  },
  
  consignop(){
    var that=this;
    that.getpagelist(that,1)
  },
  onClose() {
    this.setData({ calendarshow: false });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
  },
  withdraw(e){
    var index=e.currentTarget.dataset.index;
    var item=this.data.modellist[index]

    var data={};
    data['orderid']=item['orderid']
    data['op']='cancel';
    actbill.consignmentop(data).then(res => {

      if (res["status"] == 1) {
        wx.showToast({
          title: "取消寄售成功"
        })
        this.consignop()
      } else {
        wx.showToast({
          title: "操作失败"
        })
      }

    })
  },
  edit(e){
 
    var index=e.currentTarget.dataset.index;
    var item=this.data.modellist[index]

    var consignment = this.selectComponent("#consignment");
    consignment.showmodel(item)
  },
  onConfirm(event) {
    const [start, end] = event.detail;
    this.setData({
      calendarshow: false,
      'searchdata.startdate':`${this.formatDate(start)}`,
      'searchdata.enddate':`${this.formatDate(end)}`,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  
})